import 'package:aio/aio.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/config/app_data_cache.dart';
import 'package:app/src/http/bean/clockin/attendances.dart';
import 'package:app/src/http/bean/http_data.dart';

import '../../../config/app_data_config.dart';
import '../../../manager/user_manager.dart';
import '../../../manager/ywx_manager.dart';
import '../../../ui/route/helper/route_helper.dart';
import '../works_2023/purcontract_bean.dart';
import '../wroks/contract_bean.dart';
import '../wroks/search_bean.dart';
import '../ywx_limit.dart';
import 'package:decimal/decimal.dart';

import 'hardware_collar_bean.dart';

///设备管理：工单中心，我的工单

DateTime? _newNoticeDateTime = null; //记录最新通知的消息时间
///显示最新的提示信息。
///TicketCenter 工单中心
///Myworkorder 我的工单
bool showNewDialogWithEquipment(BuildContext context,
    EquipmentInfo? TicketCenter, EquipmentInfo? Myworkorder) {
  if (YwxIdManager.getN_ticketcenter()?.isHasLimit() ?? false) {
    //工单中心,权限判断
  } else {
    TicketCenter = null; //没有权限置空。
  }
  if (YwxIdManager.getN_Myworkorder()?.isHasLimit() ?? false) {
    //我的工单,权限判断
  } else {
    Myworkorder = null; //没有权限置空。
  }
  if (TicketCenter == null && Myworkorder == null) {
    return false;
  }
  try {
    DateTime? TicketCenterDateTime; //工单中心，最新时间。
    String? TicketCenterDateTimeStr;
    if (TicketCenter != null) {
      var AddTime = TicketCenter?.AddTime; //报修时间
      var strTime = AddTime!.replaceAll("/", "-").replaceAll("T", " ");
      TicketCenterDateTimeStr = strTime;
      TicketCenterDateTime = DateTimeUtils.stringToDateTime(strTime);
    }
    DateTime? MyworkorderDateTime; //我的工单，最新时间。
    String? MyworkorderDateTimeStr;
    if (Myworkorder != null) {
      var AddTime = Myworkorder?.DispatchingTime; //派工时间
      var strTime = AddTime!.replaceAll("/", "-").replaceAll("T", " ");
      MyworkorderDateTimeStr = strTime;
      MyworkorderDateTime = DateTimeUtils.stringToDateTime(strTime);
    }
    bool isTicketCenter = false; //最新时间是否为工单中心。
    DateTime? _newAddTime; //最新时间
    String? _newAddTimeStr;
    if (TicketCenterDateTime != null && MyworkorderDateTime != null) {
      var isAfter = TicketCenterDateTime!.isAfter(MyworkorderDateTime!);
      if (isAfter) {
        //工单中心的时间大于我的工单的时间。
        isTicketCenter = true;
        _newAddTime = TicketCenterDateTime;
        _newAddTimeStr = TicketCenterDateTimeStr;
      } else {
        //我的工单
        isTicketCenter = false;
        _newAddTime = MyworkorderDateTime;
        _newAddTimeStr = MyworkorderDateTimeStr;
      }
    } else if (TicketCenterDateTime != null) {
      //工单中心
      isTicketCenter = true;
      _newAddTime = TicketCenterDateTime;
      _newAddTimeStr = TicketCenterDateTimeStr;
    } else if (MyworkorderDateTime != null) {
      //我的工单
      isTicketCenter = false;
      _newAddTime = MyworkorderDateTime;
      _newAddTimeStr = MyworkorderDateTimeStr;
    }
    if (_newAddTime != null) {
      if (_newNoticeDateTime == null) {
        String? insertStr =
            AppDataCache.getEquipmentInfoDatetime(); //fixme 获取最新存储时间
        if (StringUtils.isNotEmpty(insertStr)) {
          try {
            var strTime = insertStr!.replaceAll("/", "-").replaceAll("T", " ");
            _newNoticeDateTime = DateTimeUtils.stringToDateTime(strTime);
          } catch (e) {
            print(
                "===============================================================_newNoticeDateTime异常：${e}");
          }
        }
      }
      if (_newNoticeDateTime != null && _newAddTime != null) {
        var isAfter = _newAddTime!.isAfter(_newNoticeDateTime!);
        if (isAfter) {
          _newNoticeDateTime = _newAddTime; //fixme 记录最新的通知时间。
          AppDataCache.setEquipmentInfoDatetime(_newAddTimeStr); //保存最新时间。
          _showNewDialog(context, TicketCenter, Myworkorder, isTicketCenter);
          return true;
        }
      } else {
        _newNoticeDateTime = _newAddTime; //fixme 记录最新的通知时间。
        AppDataCache.setEquipmentInfoDatetime(_newAddTimeStr); //保存最新时间。
        _showNewDialog(context, TicketCenter, Myworkorder, isTicketCenter);
        return true; //最新时间记录为空，没有记录过，当前提示，肯定为最新时间。
      }
    }
  } catch (e) {
    print("显示最新工单信息弹窗异常${e}");
  }
  return false;
}

///显示最新工单信息弹窗。
_showNewDialog(BuildContext? context, EquipmentInfo? TicketCenter,
    EquipmentInfo? Myworkorder, bool isTicketCenter) {
  EquipmentInfo? data;
  if (isTicketCenter) {
    data = TicketCenter;
  } else {
    data = Myworkorder;
  }
  if (context != null && data != null) {
    try {
      String title = AppStrings.of(context).Ticket_center; //工单中心
      String content = AppStrings.of(context).TicketCenterInfo;
      String okText = AppStrings.of(context).ToView; //查看
      if (!isTicketCenter) {
        title = AppStrings.of(context).Myworkorder; //我的工单
        content = AppStrings.of(context).MyworkorderInfo;
      }
      var code =
          "${AppStrings.of(context).Devicecoding}:${data.getEquipmentCode()}"; //设备编码
      var name =
          "${AppStrings.of(context).Devicename}:${data.getEquipmentName()}"; //设备名称
      if (StringUtils.isEmpty(data.getEquipmentCode())) {
        content = "$content\n$name"; //设备编码为空，不显示。其他派单就没有设备编码。
      } else {
        content = "$content\n$code\n$name";
      }
      showDialogWithAlert(context,
              title: title, content: content, okText: okText)
          ?.then((value) {
        if (value ?? false) {
          if (isTicketCenter) {
            //工单中心
            // YwxItem? item = YwxIdManager.getN_ticketcenter();
            // if (item != null) {
            //   AppRouteHelper.goTicketCenterRoute(context, item);
            // }
            //工单中心详情
            AppRouteHelper.goTicketCenterDetailsRoute(context, data);
          } else {
            //我的工单
            YwxItem? item = YwxIdManager.getN_Myworkorder();
            if (item != null) {
              // AppRouteHelper.goMyworkorderRoute(context, item);
              //我的工单详情
              AppRouteHelper.goMyworkorderDetailsRoute(context, data, item);
            }
          }
        }
      });
      VibrationUtils.vibrate(duration: 3000); //震动三秒。
    } catch (e) {
      print("显示最新工单信息弹窗异常2${e}");
    }
  }
}

///请求实体类参数
class EquipmentRequestData extends BaseBean {
  /// 设备编码
  String? Code = "";

  /// 页码；从1开始；
  String? PageIndex = "1";

  /// 每页显示个数
  String? PageSize = "20";

  /// 工厂id
  String? FactoryId = AppDataConfig.getFactory()?.FactoryId;

  ///开始时间（工单中心）
  String? StartTime = "";

  ///开始时间（我的工单）
  String? BeginTime = "";

  ///截止日期
  String? EndTime = "";

  ///工单号
  String? RepairNo = "";

  ///设备名称
  String? EquipmentName = "";

  ///等级
  String? Level = "";

  ///工单类型；-1代表全部。
  String? RepairType = "-1";

  //保修人员
  String? AddPersonId = "";

  @override
  fromJson(Map<String, dynamic> json) {
    //print("进来了：\t$json");
    Code = json["Code"]?.toString() ?? "";
    PageIndex = json["PageIndex"]?.toString() ?? "";
    PageSize = json["PageSize"]?.toString() ?? "";
    FactoryId =
        json["FactoryId"]?.toString() ?? AppDataConfig.getFactory()?.FactoryId;
    StartTime = json[" StartTime"]?.toString() ?? "";
    BeginTime = json[" StartTime"]?.toString() ?? "";
    EndTime = json[" EndTime"]?.toString() ?? "";
    RepairNo = json["RepairNo"]?.toString() ?? "";
    EquipmentName = json["EquipmentName"]?.toString() ?? "";
    Level = json["Level"]?.toString() ?? "";
    RepairType = json["RepairType"]?.toString() ?? "";
    AddPersonId = json["AddPersonId"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return EquipmentRequestData();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Code"] = Code ?? "";
    map["PageIndex"] = PageIndex ?? "";
    map["PageSize"] = PageSize ?? "";
    map["FactoryId"] = FactoryId ?? "";
    map["StartTime"] = StartTime ?? "";
    map["BeginTime"] = BeginTime ?? "";
    map["EndTime"] = EndTime ?? "";
    map["RepairNo"] = RepairNo ?? "";
    map["EquipmentName"] = EquipmentName ?? "";
    if (StringUtils.isEmpty(Level)) {
      map["Level"] = "-1"; //等级，-1代码全部。
    } else {
      map["Level"] = Level;
    }
    if (StringUtils.isEmpty(RepairType)) {
      map["RepairType"] = "-1"; //工单类型，-1代码全部。
    } else {
      map["RepairType"] = RepairType;
    }
    if (StringUtils.isEmpty(AddPersonId)) {
      map["AddPersonId"] = "0"; //保修人员，0代表全部。
    } else {
      map["AddPersonId"] = AddPersonId;
    }
    return map;
  }
}

///提交数据
class EquipmentResponseData extends BaseBean {
  //工单信息
  EquipmentInfo? equipmentInfo = null;

  //报修人员
  List<MaintenanceManInfo>? maintenanceManInfos = null;

  ///获取选中维修人员PersonId
  List<String?> getPersonIds() {
    List<String?> PersonIds = [];
    maintenanceManInfos?.forEach((element) {
      if (element.isCheck) {
        PersonIds.add(element?.PersonId);
      }
    });
    return PersonIds;
  }

  ///派工预估时长。
  String? Hours = null;

  //我的订单详情数据
  GetMyRepairOrderInfoBean? myRepairOrderInfoBean = null;

  //图片地址，多个用|隔开：	http://192.168.1.5:8888//photo/202404/10981/1713503989328_0.mp4|http://192.168.1.5:8888//photo/202404/10981/1713503989427_1.jpg|http://192.168.1.5:8888//photo/202404/10981/1713503989427_2.jpg
  String? Files = null;

  //五金列表数据（五金领用）
  List<HardwareBean>? hardwareDatas = null;

  //五金领用提交数据
  SubmitHardwareReceive? submitHardwareReceive = SubmitHardwareReceive();

  @override
  fromJson(Map<String, dynamic> json) {}

  @override
  instance() {
    // TODO: implement instance
    return EquipmentResponseData();
  }

  @override
  Map<String, dynamic> toJson() {
    var map = <String, dynamic>{};
    //派工：{ Id:0, Hours:1.2, PersonIds:['10981','10837'] }
    map["Id"] = equipmentInfo?.Id ?? ""; //工单id
    map["Hours"] = Hours ?? ""; //派工预估时长
    map["PersonIds"] = getPersonIds(); //维修人员
    map["Files"] = Files ?? ""; //图片地址
    return map;
  }
}

///设备实体类(工单信息)
class EquipmentInfo extends BaseBean {
  String? Id = "";

  /// 工单号
  String? RepairNo = "";

  ///等级；紧急等级 0-普通(自动发布) 1-强制(强制自动) 2-紧急(报修)
  String? UrgencyLevel = "";

  String? getUrgencyLevelName(BuildContext context) {
    if (UrgencyLevel == "0") {
      return AppStrings.of(context).UrgencyLevel0; //普通
    } else if (UrgencyLevel == "1") {
      return AppStrings.of(context).UrgencyLevel1; //强制
    } else if (UrgencyLevel == "2") {
      return AppStrings.of(context).UrgencyLevel2; //紧急
    }
    return "";
  }

  static List<RollerBean>? UrgencyLevelDatas = null;

  ///获取等级数据集合
  static List<RollerBean>? getUrgencyLevels(BuildContext context) {
    if (UrgencyLevelDatas == null || UrgencyLevelDatas!.length <= 0) {
      List<RollerBean>? datas = [];
      RollerBean bean = RollerBean();
      bean.key = "0";
      bean.value = AppStrings.of(context).UrgencyLevel0; //普通
      datas.add(bean);
      RollerBean bean1 = RollerBean();
      bean1.key = "1";
      bean1.value = AppStrings.of(context).UrgencyLevel1; //强制
      datas.add(bean1);
      RollerBean bean2 = RollerBean();
      bean2.key = "2";
      bean2.value = AppStrings.of(context).UrgencyLevel2; //紧急
      datas.add(bean2);
      UrgencyLevelDatas = datas;
    }
    return UrgencyLevelDatas;
  }

  /// 一级设备编码
  String? EquipmentCode1 = "";

  /// 一级设备编码名称；其他派单的 工单名称
  String? EquipmentName1 = "";

  ///二级设备编码
  String? EquipmentCode2 = "";

  ///二级设备编码名称
  String? EquipmentName2 = "";

  ///三级设备编码
  String? EquipmentCode3 = "";

  ///三级设备编码名称
  String? EquipmentName3 = "";

  //获取等级
  String? getLv() {
    if (StringUtils.isNotEmpty(EquipmentCode3) ||
        StringUtils.isNotEmpty(EquipmentName3)) {
      return "3"; //三级设备
    } else if (StringUtils.isNotEmpty(EquipmentCode2) ||
        StringUtils.isNotEmpty(EquipmentName2)) {
      return "2"; //二级设备
    }
    return "1"; //一级设备
  }

  ///判断是否为一级设备
  bool isLv1() {
    return getLv() == "1";
  }

  ///判断是否为二级设备
  bool isLv2() {
    return getLv() == "2";
  }

  ///判断是否为三级设备
  bool isLv3() {
    return getLv() == "3";
  }

  ///获取设备编码
  String? getEquipmentCode() {
    if (StringUtils.isNotEmpty(EquipmentCode3)) {
      return EquipmentCode3;
    } else if (StringUtils.isNotEmpty(EquipmentCode2)) {
      return EquipmentCode2;
    }
    return EquipmentCode1;
  }

  ///获取设备名称
  String? getEquipmentName() {
    if (StringUtils.isNotEmpty(EquipmentName3)) {
      return EquipmentName3;
    } else if (StringUtils.isNotEmpty(EquipmentName2)) {
      return EquipmentName2;
    }
    return EquipmentName1;
  }

  ///工单类型;维修类型 0-定期保养工单系统 1-配置强制性工单 2-故障报修工单 3-其他工单 已作废，已调整了显示文件。
  ///工单类型：维修类型 0-定期保养工单 1-强制性工单 2-故障报修工单 3-其他工单       以这个为准。
  String? RepairType = "";

  String? getRepairTypeName(BuildContext context) {
    if (RepairType == "0") {
      return AppStrings.of(context).RepairType0; //定期保养工单
    } else if (RepairType == "1") {
      return AppStrings.of(context).RepairType1; //强制性工单
    } else if (RepairType == "2") {
      return AppStrings.of(context).RepairType2; //故障报修工单
    } else if (RepairType == "3") {
      return AppStrings.of(context).RepairType3; //其他工单
    }
    return "";
  }

  ///判断是否为其他派单
  bool isOtherRepairType() {
    if (RepairType == "3") {
      return true;
    }
    return false;
  }

  ///判断是否为强制性工单；(强制性工单，没有五金领用)
  bool isRepairType1() {
    if (RepairType == "1") {
      return true;
    }
    return false;
  }

  static List<RollerBean>? RepairTypeDatas = null;

  ///工单类型数据集合
  static List<RollerBean>? getRepairTypeDatas(BuildContext context) {
    if (RepairTypeDatas == null || RepairTypeDatas!.length <= 0) {
      List<RollerBean>? datas = [];
      RollerBean bean = RollerBean();
      bean.key = "0";
      bean.value = AppStrings.of(context).RepairType0; //定期保养工单
      datas.add(bean);
      RollerBean bean1 = RollerBean();
      bean1.key = "1";
      bean1.value = AppStrings.of(context).RepairType1; //强制性工单
      datas.add(bean1);
      RollerBean bean2 = RollerBean();
      bean2.key = "2";
      bean2.value = AppStrings.of(context).RepairType2; //故障报修工单
      datas.add(bean2);
      RollerBean bean3 = RollerBean();
      bean3.key = "3";
      bean3.value = AppStrings.of(context).RepairType3; //其他工单
      datas.add(bean3);
      RepairTypeDatas = datas;
    }
    return RepairTypeDatas;
  }

  ///报修时间
  String? AddTime = "";

  ///报修人员
  String? AddPersonName = "";

  ///工序
  String? ProcessName = "";

  ///状态 0-待派单 1-已派单 2-维修中(有人接单) 3-已完成
  String? State = "";

  String? getSateName(BuildContext context) {
    if (State == "0") {
      return AppStrings.of(context).DeviceState0;
    } else if (State == "1") {
      return AppStrings.of(context).DeviceState1;
    } else if (State == "2") {
      return AppStrings.of(context).DeviceState2;
    } else if (State == "3") {
      return AppStrings.of(context).DeviceState3;
    }
    return "";
  }

  ///判断该订单，是否已接单
  bool isState2(List<MaintenanceManInfo>? RepairPersonInfo) {
    if (State == "2") {
      var PersonId = UserManager.getUserInfo()?.PersonId;
      //设备维修人员，通过PersonId找到自己，看看自己有没有接单。
      var jiedan = false;
      RepairPersonInfo?.forEach((element) {
        if (PersonId == element.PersonId) {
          if (StringUtils.isEmpty(element?.ConfirmTime)) {
            //接单时间为空，说明该通知单是其他协同人员接的单，自己还没有接单。可以继续接单。
            jiedan = false; //未接单
          } else {
            jiedan = true; //已接单。
          }
        }
      });
      return jiedan;
      // return true;
    }
    return false;
  }

  ///第几条列表；相当与序号；服务器给的序号。目前用不到。
  String? ROWN = "";

  ///文件附件
  String? Files = null;

  ///获取文件附件集合。
  List<String>? getFiles() {
    var f = Files?.trim();
    if (f != null && f.length > 0 && f != "[]") {
      return f.split(",");
    }
    return null;
  }

  ///安装日期 2024-03-25
  String? InstallDate = null;

  ///安装位置 "InstallPosition": "666",
  String? InstallPosition = null;

  //设备型号 "Model": "666",
  String? Model = null;

  //工厂名称 "FactoryName": "江花玻璃（庄桥）",
  String? FactoryName = null;

  //供应商 "SupplierName": "北仑官方店",
  String? SupplierName = null;

  //制造商 "ManufacturerName": "南玻",
  String? ManufacturerName = null;

  //设备状态 "EquipmentType": "正常"
  String? EquipmentType = null;

  ///完成时间
  String? CompleteTime = null;

  ///管理人姓名
  String? ManagePersonName = null;

  //责任人姓名
  String? ResponsiblePersonName = null;

  ///备注
  String? Remark = null;

  //派工时间
  String? DispatchingTime = null;

  @override
  fromJson(Map<String, dynamic> json) {
    //print("进来了：\t$json");
    Id = json["Id"]?.toString() ?? "";
    RepairNo = json["RepairNo"]?.toString() ?? "";
    UrgencyLevel = json["UrgencyLevel"]?.toString() ?? "";
    EquipmentCode1 = json["EquipmentCode1"]?.toString() ?? "";
    EquipmentName1 = json["EquipmentName1"]?.toString() ?? ""; //工单名称
    EquipmentCode2 = json["EquipmentCode2"]?.toString() ?? "";
    EquipmentName2 = json["EquipmentName2"]?.toString() ?? "";
    EquipmentCode3 = json["EquipmentCode3"]?.toString() ?? "";
    EquipmentName3 = json["EquipmentName3"]?.toString() ?? "";
    RepairType = json["RepairType"]?.toString() ?? "";
    AddTime = json["AddTime"]?.toString() ?? "";
    AddPersonName = json["AddPersonName"]?.toString() ?? "";
    ProcessName = json["ProcessName"]?.toString() ?? "";
    State = json["State"]?.toString() ?? "";
    ROWN = json["ROWN"]?.toString() ?? "";
    // Files = setGenericFromJson(json, 'Files', <String>[], "");
    Files = json["Files"]?.toString() ?? "";
    InstallDate = json["InstallDate"]?.toString() ?? "";
    InstallPosition = json["InstallPosition"]?.toString() ?? "";
    Model = json["Model"]?.toString() ?? "";
    FactoryName = json["FactoryName"]?.toString() ?? "";
    SupplierName = json["SupplierName"]?.toString() ?? "";
    ManufacturerName = json["ManufacturerName"]?.toString() ?? "";
    EquipmentType = json["EquipmentType"]?.toString() ?? "";
    CompleteTime = json["CompleteTime"]?.toString() ?? "";
    ManagePersonName = json["ManagePersonName"]?.toString() ?? "";
    ResponsiblePersonName = json["ResponsiblePersonName"]?.toString() ?? "";
    Remark = json["Remark"]?.toString() ?? "";
    DispatchingTime = json["DispatchingTime"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return EquipmentInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["Id"] = Id;
    map["RepairNo"] = RepairNo;
    map["UrgencyLevel"] = UrgencyLevel;
    map["EquipmentName1"] = EquipmentName1;
    map["EquipmentCode2"] = EquipmentCode2;
    map["EquipmentName2"] = EquipmentName2;
    map["EquipmentCode3"] = EquipmentCode3;
    map["EquipmentName3"] = EquipmentName3;
    map["RepairType"] = RepairType;
    map["AddTime"] = AddTime;
    map["AddPersonName"] = AddPersonName;
    map["ProcessName"] = ProcessName;
    map["State"] = State;
    map["ROWN"] = ROWN;
    map["Files"] = Files;
    map["InstallDate"] = InstallDate;
    map["InstallPosition"] = InstallPosition;
    map["Model"] = Model;
    map["FactoryName"] = FactoryName;
    map["SupplierName"] = SupplierName;
    map["ManufacturerName"] = ManufacturerName;
    map["EquipmentType"] = EquipmentType;
    map["CompleteTime"] = CompleteTime;
    map["ManagePersonName"] = ManagePersonName;
    map["ResponsiblePersonName"] = ResponsiblePersonName;
    map["Remark"] = Remark;
    map["DispatchingTime"] = DispatchingTime;
    return map;
  }
}

///维修工实体类
class MaintenanceManInfo extends BaseBean {
  //id
  String? PersonId = "";

  ///名字
  String? PersonName = "1";

  /// 部门(班组)
  String? Column1 = "";
  String? DeptName = "";

  ///获取班组
  getClassName() {
    if (StringUtils.isNotEmpty(DeptName)) {
      return DeptName; //现在取这个。
    }
    return Column1 ?? ""; //旧版本取的是这个。
  }

  ///工作岗位
  String? Job = "";

  ///基本工资月
  String? BaseWageMonth = "";
  String? WorkMoney = "";

  ///预估工时
  String? WorkHours = "";

  //CompleteTime 完工时间
  String? CompleteTime = "";

  //ConfirmTime 接单时间
  String? ConfirmTime = "";

  //是否选中，自己本地加的字段。
  bool isCheck = false;

  // "PersonName": "王尚文",
  // "WorkHours": 1.00,
  // "DeptName": "软件部",
  // "Job": "",
  // "CompleteTime": "",
  // "ConfirmTime": "",
  // "WorkMoney": 20.00

  @override
  fromJson(Map<String, dynamic> json) {
    //print("进来了：\t$json");
    PersonId = json["PersonId"]?.toString() ?? "";
    PersonName = json["PersonName"]?.toString() ?? "";
    Column1 = json["Column1"]?.toString() ?? "";
    Job = json["Job"]?.toString() ?? "";
    BaseWageMonth = json["BaseWageMonth"]?.toString() ?? "";
    WorkMoney = json["WorkMoney"]?.toString() ?? "";
    WorkHours = json["WorkHours"]?.toString() ?? "";
    DeptName = json["DeptName"]?.toString() ?? "";
    CompleteTime = json["CompleteTime"]?.toString() ?? "";
    ConfirmTime = json["ConfirmTime"]?.toString() ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return MaintenanceManInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["PersonId"] = PersonId ?? "";
    map["PersonName"] = PersonName ?? "";
    map["Column1"] = Column1 ?? "";
    map["Job"] = Job ?? "";
    map["BaseWageMonth"] = BaseWageMonth ?? "";
    map["WorkMoney"] = WorkMoney ?? "";
    map["WorkHours"] = WorkHours ?? "";
    map["DeptName"] = DeptName ?? "";
    map["CompleteTime"] = CompleteTime ?? "";
    map["ConfirmTime"] = ConfirmTime ?? "";
    return map;
  }
}

///我的工单详情数据实体类
class GetMyRepairOrderInfoBean extends BaseBean {
  ///设备信息
  EquipmentInfo? OrderInfo = null;

  ///维修人员信息
  List<MaintenanceManInfo>? RepairPersonInfo = null;

  ///获取协同人员姓名;(除了自己以外的维修人员)
  String getCollaboratorName() {
    // print("维修人员：${RepairPersonInfo?.length}");
    var PersonId = UserManager.getUserInfo()?.PersonId;
    String _name = "";
    RepairPersonInfo?.forEach((element) {
      // print(
      //     "${PersonId}\t${element.PersonId}\t${(element.PersonId != PersonId)}");
      if (element.PersonId != PersonId) {
        if (StringUtils.isEmpty(_name)) {
          _name = element.PersonName ?? "";
        } else {
          var PersonName = element.PersonName;
          if (StringUtils.isNotEmpty(PersonName)) {
            _name = "$_name,$PersonName"; //多个协同人员，用逗号隔开。
          }
        }
      }
    });
    // print("维修人员：${_name}");
    return _name; //不写新字段了，还是实时计算比较好，因为数据可能会刷新。
  }

  ///获取预计工时；（取维修人员列表里的第一个人的时间就可以了，所有人的时间都是相同的。）
  String getWorkHours() {
    if (RepairPersonInfo != null && RepairPersonInfo!.length > 0) {
      // print("预计工时：${RepairPersonInfo![0]?.WorkHours}");
      return RepairPersonInfo![0]?.WorkHours ?? "";
    }
    return "";
  }

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    OrderInfo = setGenericFromJson(json, 'OrderInfo', EquipmentInfo(), "");
    RepairPersonInfo = setGenericFromJson(
        json, 'RepairPersonInfo', <MaintenanceManInfo>[], MaintenanceManInfo());
  }

  @override
  instance() {
    // TODO: implement instance
    return GetMyRepairOrderInfoBean();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["OrderInfo"] = OrderInfo;
    map["RepairPersonInfo"] = RepairPersonInfo;
    return map;
  }
}
